package boun.center;

import java.util.ArrayList;

import android.content.Context;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FinalExamListAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<Course> courses;
	public FinalExamListAdapter(Context c, Pair<String, String> p) throws Exception{
		context = c;
		ExamDownloader e = new ExamDownloader(p.first,p.second);
		courses = e.fetchCourses();
	}
	@Override
	public int getCount() {
		return courses.size();
	}

	@Override
	public Object getItem(int position) {
		return courses.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null){
			LayoutInflater inflater	= LayoutInflater.from(context);
			convertView = inflater.inflate(R.layout.final_dates,parent,false);
		}
		TextView CourseName = (TextView)convertView.findViewById(R.id.course_name);
		CourseName.setText(courses.get(position).getName());
		TextView Hours = (TextView)convertView.findViewById(R.id.hours);
		Hours.setText(courses.get(position).getHours());
		TextView finalDates = (TextView)convertView.findViewById(R.id.final_dates);
		finalDates.setText(courses.get(position).getFinalDate());
		TextView finalSlot = (TextView) convertView.findViewById(R.id.final_slot);
		finalSlot.setText(courses.get(position).getFinalSlot());
		TextView finalPlace = (TextView) convertView.findViewById(R.id.final_place);
		finalPlace.setText(courses.get(position).getFinalPlace());
		ImageView finalImage = (ImageView) convertView.findViewById(R.id.final_image);
		finalImage.setImageResource(R.drawable.ic_tab_course_selected);
		return convertView;
	}
	
}
